/**
 * Copyright &copy; 2012-2016 <a href="https://git.oschina.net/zdw2016/webbase5">Webbase</a> All rights reserved.
 */
package com.foreveross.webbase.projectdemo.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.foreveross.webbase.common.config.Global;
import com.foreveross.webbase.common.persistence.Page;
import com.foreveross.webbase.common.web.BaseController;
import com.foreveross.webbase.common.utils.StringUtils;
import com.foreveross.webbase.projectdemo.entity.PPt;
import com.foreveross.webbase.projectdemo.service.PPtService;

/**
 * 申请表和类型之间关联表Controller
 * @author yangwanli
 * @version 2017-03-21
 */
@Controller
@RequestMapping(value = "${adminPath}/projectdemo/pPt")
public class PPtController extends BaseController {

	@Autowired
	private PPtService pPtService;
	
	@RequiresPermissions("projectdemo:pPt:view")
	@RequestMapping(value = {"list", ""})
	public String list(PPt pPt) {
		Page<PPt> page = pPtService.findPage(new Page<PPt>(request(), response()), pPt); 
		attr("page", page);
		return "projectdemo/pPtList";
	}

	@RequiresPermissions("projectdemo:pPt:view")
	@RequestMapping("form")
	public String form(String id) {
		if(StringUtils.isNotEmpty(id)) {
			PPt pPt=pPtService.get(id);
			attr("pPt", pPt);
		} else {
			attr("pPt", new PPt());
		}
		return "projectdemo/pPtForm";
	}

	@RequiresPermissions("projectdemo:pPt:edit")
	@RequestMapping("save")
	public String save(PPt pPt, RedirectAttributes redirectAttributes) {
		if (!beanValidator(redirectAttributes, pPt)){
			return form(pPt.getId());
		}
		pPtService.save(pPt);
		addMessage(redirectAttributes, "保存申请表和类型之间关联表成功");
		return "redirect:"+Global.getAdminPath()+"/projectdemo/pPt/?repage";
	}
	
	@RequiresPermissions("projectdemo:pPt:edit")
	@RequestMapping("delete")
	public String delete(@RequestParam String id, RedirectAttributes redirectAttributes) {
		pPtService.delete(id);
		addMessage(redirectAttributes, "删除申请表和类型之间关联表成功");
		return "redirect:"+Global.getAdminPath()+"/projectdemo/pPt/?repage";
	}

}